﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FilStartUps.DAL;

namespace FilStartUps
{
    public partial class ThreadReply : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated)
            {
                LinkButton lkHome = (LinkButton)FilStartUps_PageNav1.FindControl("lbLgout");
                LinkButton lkProfile = (LinkButton)FilStartUps_PageNav1.FindControl("lbProfile");
                lkProfile.Visible = true;
                lkHome.Visible = true;
            }
        }

        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            using (FilStartUpsEntities db_connect = new FilStartUpsEntities())
            {
                var user = db_connect.Members.Where(p => p.emailaddress.Equals(User.Identity.Name)).SingleOrDefault();
                ForumReply forumreply = new ForumReply();
                forumreply.datereplied = DateTime.Now;
                forumreply.forumreplystatus = true;
                forumreply.memberidFK = user.memberidPK;
                forumreply.replydescription = txtreplymessage.Text;
                forumreply.forumthreadidFK = Convert.ToInt32(Request.QueryString["t"].Trim());
                db_connect.ForumReplies.Add(forumreply);
                db_connect.SaveChanges();
            }

            Response.Redirect("~/ShowThread.aspx?t=" + Request.QueryString["t"].Trim());
        }

        protected void CheckEditorNotEmptyServerSide(object sender, ServerValidateEventArgs args)
        {
            bool valid = args.Value.Length > 0;
            args.IsValid = valid;
        }
    }
}